from rest_framework.throttling import SimpleRateThrottle


# 控制访问频率
class Throttles(SimpleRateThrottle):
    # 访问频率10次一分钟
    rate = '10/m'

    def get_cache_key(self, request, view):
        return self.get_ident(request)


# 全局访问频率控制，在setting设置
class RateThrottle(SimpleRateThrottle):
    scope = "visit_rate"

    def get_cache_key(self, request, view):
        return self.get_ident(request)
